package vip.ola.manage.dataclean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vip.ola.core.common.util.MyLog;
import vip.ola.manage.common.service.RpcCommonService;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;


@Component
public class DataCleanScheduled {

    @Autowired
    private RpcCommonService rpcCommonService;


    private static final MyLog _log = MyLog.getLog(DataCleanScheduled.class);

    /**
     * 每天凌晨4天清理
     */
    @Scheduled(cron = "0 0 4 * * * ?")
    public void handleExpireOrder() {
        LocalDateTime now = LocalDateTime.now();
        _log.info("当前时间:  "+now);
        LocalDateTime startDay = LocalDateTime.now().plusDays(-2);
        LocalDateTime endDay = LocalDateTime.now().plusDays(-1);
        LocalDateTime startTime = LocalDateTime.of(startDay.toLocalDate(), LocalTime.MIN);
        LocalDateTime endTime = LocalDateTime.of(endDay.toLocalDate(), LocalTime.MIN);
        //开始时间的零点
        _log.info("开始时间的零点:  "+startTime);

        //结束时间的零点
        _log.info("结束时间的零点:  "+endTime);
        List<String> cleanItem = new ArrayList<>();
        cleanItem.add("codeOrder");
        cleanItem.add("codeUser");
        cleanItem.add("codeInfo");
        cleanItem.add("codeAccountHistory");
        cleanItem.add("passageSett");
        cleanItem.add("payOrder");
        cleanItem.add("notify");
        cleanItem.add("bill");
        cleanItem.add("settRecord");
        cleanItem.add("mchHistory");
        cleanItem.add("agentHistory");
        cleanItem.add("sysLog");
        _log.info("wait clean item->{}",cleanItem);
 //       boolean isOk = rpcCommonService.rpcSysService.cleanData(cleanItem, startTime, endTime);
        _log.info("数据清理完成, isOk={}",true);
    }

}
